home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
othergnu
/
ispell.zoo
/
ispell.el
< prev
next >
Wrap
Lisp/Scheme
|
1990-03-06
|
26KB
|
572 lines
;; ISPELL.EL -- Spelling correction interface for GNU EMACS using "ispell".
;; Copyright (C) 1988 Ashwin Ram.
;;
;; This file is not part of the GNU Emacs distribution (yet).
;;
;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY. No author or distributor
;; accepts responsibility to anyone for the consequences of using it
;; or for whether it serves any particular purpose or works at all,
;; unless he says so in writing. Refer to the GNU Emacs General Public
;; License for full details.
;; Everyone is granted permission to copy, modify and redistribute
;; this file, but only under the conditions described in the
;; GNU Emacs General Public License. A copy of this license is
;; supposed to have been given to you along with GNU Emacs so you
;; can know your rights and responsibilities. It should be in a
;; file named COPYING. Among other things, the copyright notice
;; and this notice must be preserved on all copies.
(provide 'ispell)
;; Comments, corrections, and improvements should be sent to:
;;
;; Ashwin Ram
;;
;; ARPA: Ram-Ashwin@cs.yale.edu
;; UUCP: {decvax,ucbvax,harvard,cmcl2,...}!yale!Ram-Ashwin
;; BITNET: Ram@yalecs
;;; MODIFICATION HISTORY:
;;; Ray Moody ARPA: ray@maxwell.physics.purdue.edu
;;; UUCP: ...!pur-phy!ray
;;; BITNET: moody@purccvm (going away soon....)
;;; Inserted a missing save-excursion in ispell-check-version-compatibility.
;;; 3/30/89.
;;; Ashwin Ram ARPA: Ram-Ashwin@cs.yale.edu
;;; UUCP: ...!{decvax, linus, seismo}!yale!Ram-Ashwin
;;; BITNET: Ram@yalecs
;;; Added flag to allow filters that don't produce single column output.
;;; 3/20/88.
;;; Added version compatibility code because of all the confusion.
;;; 11/19/87.
;;; Added variable to control embedded word checking (nice in troff but a pain otherwise).
;;; 10/26/87.
;;; Interactive word completion.
;;; 8/14/87.
;;; Detex before checking spelling.
;;; Made options more mnemonic, prompt and error messages better.
;;; Added highlighting of misspelled word.
;;; Query-replace all occurrences of misspelled word through buffer.
;;; Allow customization of personal dictionary.
;;; Moved temporary file to /tmp.
;;; Added check for dead ispell process to avoid infinite loop.
;;; Avoid repeated querying for same word in same buffer.
;;; 7/6/87.
;;; Walt Buehring
;;; Texas Instruments - Computer Science Center
;;; ARPA: Buehring%TI-CSL@CSNet-Relay
;;; UUCP: {smu, texsun, im4u, rice} ! ti-csl ! buehring
;;; ispell-region and associated routines added by
;;; Perry Smith
;;; pedz@bobkat
;;; Tue Jan 13 20:18:02 CST 1987
;;; extensively modified by Mark Davies and Andrew Vignaux
;;; {mark,andrew}@vuwcomp
;;; Sun May 10 11:45:04 NZST 1987
;;; Depends on the ispell program snarfed from MIT-PREP in early 1986.
;;; CUSTOMIZATION:
;;; To fully install this, add this file to your GNU lisp directory and
;;; compile it with M-X byte-compile-file. Then add the following to the
;;; appropriate init file:
;;; (autoload 'ispell-word "ispell" "Check spelling of word at or before point" t)
;;; (autoload 'ispell-complete-word "ispell" "Complete word at or before point" t)
;;; (autoload 'ispell-region "ispell" "Check spelling of every word in the region" t)
;;; (autoload 'ispell-buffer "ispell" "Check spelling of every word in the buffer" t)
;;; You might want to bind ispell-word and ispell-complete word to keys.
;;; You might also want to set the ispell customization variables, e.g.:
;;; (setq-default ispell-words-have-boundaries t) ;; To change the default value.
;;; or, (setq ispell-words-have-boundaries t) ;; To change a local value (perhaps inside a mode hook).
;;; Look at variables starting with "ispell-" to see what you get.
;;; If run on a heavily loaded system, the initial sleep time in ispell-init-process
;;; may need to be increased.
;;; If you count special characters like ' (apostrophe) or - (hyphen) as part of
;;; a word, set their syntax table entries as follows:
;;; (modify-syntax-entry ?' "w " ispell-syntax-table)
;;; (modify-syntax-entry ?- "w " ispell-syntax-table)
;;; Similarly, if you don't want something to count as a word character, set its
;;; syntax entry to ". ".
(defconst ispell-version "2.0.01") ;; Check against output of "ispell -v".
(defconst ispell-out-name " *ispell*"
"Name of the buffer that is associated with the 'ispell' process")
(defconst ispell-temp-name " *ispell-temp*"
"Name of the temporary buffer that 'ispell-region' uses to hold the
filtered region")
(defvar ispell-program-name "ispell"
"*Program invoked by ispell-word and ispell-region commands.")
(defvar ispell-dictionary
nil
"*Personal dictionary file containing a list of words, one to a line.
If nil, defaults to ispell's normal default (usually ~/.ispell_words).")
(defvar ispell-words-have-boundaries t
"*If nil, a misspelled word matches embedded words too. This is useful in
nroff/troff, where a misspelled word may be hidded (e.g., \fIword\fB), and a
pain otherwise.")
(defvar ispell-highlight nil
"*If non-nil, misspelled words are highlighted. See the function highlight-region.")
(defvar ispell-syntax-table nil
"*Syntax table used by ispell to find word boundaries. You may change syntax
entries to, say, allow ' and - to be part of words, or not, as you prefer.")
(if (null ispell-syntax-table)
;; The following assumes that the standard-syntax-table
;; is static. If you add words with funky characters
;; to your dictionary, the following may have to change.
(progn
(setq ispell-syntax-table (make-syntax-table))
;; Make certain characters word constituents
;; (modify-syntax-entry ?' "w " ispell-syntax-table)
;; (modify-syntax-entry ?- "w " ispell-syntax-table)
;; Get rid on existing word syntax on certain characters
(modify-syntax-entry ?0 ". " ispell-syntax-table)
(modify-syntax-entry ?1 ". " ispell-syntax-table)
(modify-syntax-entry ?2 ". " ispell-syntax-table)
(modify-syntax-entry ?3 ". " ispell-syntax-table)
(modify-syntax-entry ?4 ". " ispell-syntax-table)
(modify-syntax-entry ?5 ". " ispell-syntax-table)
(modify-syntax-entry ?6 ". " ispell-syntax-table)
(modify-syntax-entry ?7 ". " ispell-syntax-table)
(modify-syntax-entry ?8 ". " ispell-syntax-table)
(modify-syntax-entry ?9 ". " ispell-syntax-table)
(modify-syntax-entry ?$ ". " ispell-syntax-table)
(modify-syntax-entry ?% ". " ispell-syntax-table)))
(defun ispell-word (&optional quietly)
"Check spelling of word at or before dot.
If word not found in dictionary, display possible corrections in a window
and let user select."
(interactive)
(let* ((current-syntax (syntax-table))
start end word poss replace)
(unwind-protect
(save-excursion
(set-syntax-table ispell-syntax-table) ;; Ensure syntax table is reasonable
(if (not (looking-at "\\w"))
(re-search-backward "\\w" (point-min) 'stay)) ;; Move backward for word if not already on one
(re-search-backward "\\W" (point-min) 'stay) ;; Move to start of word
(or (re-search-forward "\\w+" nil t) ;; Find start and end of word
(error "No word to check."))
(setq start (match-beginning 0)
end (match-end 0)
word (buffer-substring start end)))
(set-syntax-table current-syntax))
(ispell-init-process) ;; erases ispell output buffer
(or quietly (message "Checking spelling of %s..." (upcase word)))
(save-excursion
(set-buffer ispell-out-name)
(send-string ispell-process (concat word "\n"))
(while (progn ;; Wait until we have a complete line
(goto-char (point-max))
(/= (preceding-char) ?\n))
(accept-process-output ispell-process))
(goto-char (poi